
//#include "btBulletDynamicsCommon.h"
#include <osgDB/ReadFile>
#include "PHYModeler.h"
#include "PHYFactory.h"
#include <iostream>
using namespace std;

PHYFactory::PHYFactory()
{
}

PHYCollisionObj* PHYFactory::CreateSphere(double iRadius, PHYVector &iOrigin)
{
	cout << "PHYFactory::CreateSphere" << endl;
	osg::Geode *pGeode = new osg::Geode();
	osg::Sphere *pSph = new osg::Sphere(osg::Vec3d(0,0,0),iRadius);
	PHYSphere *sph = new PHYSphere(pGeode, iRadius, iOrigin);
	osg::ShapeDrawable* sphDrawable = new osg::ShapeDrawable(pSph);

	pGeode->addDrawable(sphDrawable);
	PHYModeler *pMod = PHYModeler::getInstance();
	if(pMod)
		pMod->AddCollisionObject(sph);		
	
	return sph;
}

PHYCollisionObj* PHYFactory::CreateBox(double iX, double iY, double iZ, PHYVector &iOrigin)
{
	cout << "PHYFactory::CreateBox" << endl;
	osg::Geode *pGeode = new osg::Geode();
	osg::Box *pBox = new osg::Box(osg::Vec3d(0,0,0),iX, iY, iZ);
	PHYBox *box = new PHYBox(pGeode, iX, iY, iZ, iOrigin);
	osg::ShapeDrawable* boxDrawable = new osg::ShapeDrawable(pBox);

	pGeode->addDrawable(boxDrawable);

	//osg::PositionAttitudeTransform* pTransform = box->getTransform();
	
	PHYModeler *pMod = PHYModeler::getInstance();
	if(pMod)
		pMod->AddCollisionObject(box);		
	return box;
}

PHYCollisionObj* PHYFactory::CreateConvex(char *filename, PHYVector &iOrigin)
{
	osg::Node* pNode = NULL;
	pNode = osgDB::readNodeFile(filename);
	PHYConvex *pConvex = new PHYConvex(pNode,filename,iOrigin);

	PHYModeler *pMod = PHYModeler::getInstance();
	if(pMod)
		pMod->AddCollisionObject(pConvex);		

	return pConvex;
}
